package com.haisen.service.impl;

import com.alibaba.fastjson.JSON;
import com.haisen.dataobject.entity.ColumnsMap;
import com.haisen.dataobject.mapper.base.ColumnsMapMapper;
import com.haisen.dataobject.mapper.base.TblFieldMapper;
import com.haisen.service.ColumnService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@Slf4j
public class ColumnServiceImpl implements ColumnService{

    /**
     * 字段中英文名称映射
     */
    @Autowired
      private ColumnsMapMapper columnsMapMapper;

    /**
     * 表格字段名称
     */
      @Autowired
      private TblFieldMapper tblFieldMapper;

    @Override
    public void create(String tableName, Map<Integer, String> fieldsMap) {

        /*//1、字段中名称映射，中文->英文
         List<ColumnsMap> columnsMapList = columnsMapMapper.selectAll();
         List<Columns> tbFieldList = new ArrayList<>();
        //map(1,号码：string)
        for (Map.Entry<Integer,String> entry : fieldsMap.entrySet()){
            String[] fieldNameAndType = entry.getValue().split(":");
            //将中文名称转成标准化的英文字段名
            //2、查映射字段中存在的
             columnsMapList.stream().map(o ->{
                if(o.getAliasList().contains(fieldNameAndType[0])) {
                   return tbFieldList.add(new Columns(tableName,fieldNameAndType[0],o.getName(),fieldNameAndType[1],entry.getKey()));
                } else{
                    return tbFieldList.add(new Columns(tableName,fieldNameAndType[0],"",fieldNameAndType[1],entry.getKey()));
                }
            }).count();
        }
      log.info("{}", JSON.toJSONString(tbFieldList));*/
    }
}
